package cn.gson.crm.control.dept;


import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.control.base.BaseServlet;
import cn.gson.crm.model.dao.DeptDao;
import cn.gson.crm.model.entity.Dept;

@WebServlet("/dept/manager")
public class DeptManagerServlet extends BaseServlet{
	private DeptDao deptDao = new DeptDao();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String nowpage = request.getParameter("nowpage");
		String deptNameStr = (String)request.getSession().getAttribute("deptNameStr");
		request.setAttribute("delLogo", 0);
		if(deptNameStr != null && !deptNameStr.isEmpty()){
			request.getSession().setAttribute("deptNameStr", "");
			request.setAttribute("delError", deptNameStr);
			request.setAttribute("delLogo", 1);
		}
		
			String deptName = request.getParameter("deptName");
			String deptManager = request.getParameter("deptManager");
			String deptParent = request.getParameter("deptParent");
			List<Dept> allDeptList;
			allDeptList = deptDao.getList();
			request.setAttribute("allDeptList", allDeptList);
			int page = deptDao.getDeptPageSum(deptName,deptManager,deptParent);
			request.getSession().setAttribute("pageSum", page);
			if(nowpage == null){
			nowpage = "1";
			}
			request.getSession().setAttribute("nowpage", nowpage);
			List<Dept> deptList = deptDao.getPageDeptListByType(Integer.parseInt(nowpage),deptName,deptManager,deptParent);
			request.setAttribute("deptList", deptList);
			request.setAttribute("queryString", noPageQueryString());
			forward("dept/dept_manager.jsp");
	
	}

}
